<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">


<!--选择外购件库存模态框-->
<div class="modal fade" id="modal-select-purchase">
    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">外购件库在库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="modalQueryForm">
                                    <div class="row" id="HiddenDiv">
                                        <div class="form-inline">
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>
                                                    生产状态
                                                </label>
                                                <select id="proProductionStatus" name="proProductionStatus"
                                                        class="form-control select">
                                                    <option value="" selected="selected">全部</option>
                                                    <option value="-1">无状态</option>
                                                    <option value="1">未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">取消</option>
                                                    <option value="5">暂缓</option>
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode" name="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>项目名称</label>
                                                <input type="text" id="ityProName" name="ityProName"
                                                       class="form-control"
                                                       placeholder="请输入项目名称">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode" name="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>
                                                    物料描述
                                                </label>
                                                <input type="text" id="ityMatDesc" name="ityMatDesc"
                                                       class="form-control"
                                                       placeholder="请输入物料描述">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>
                                                    物料编码
                                                </label>
                                                <input type="text" id="ityMatCode" name="ityMatCode"
                                                       class="form-control"
                                                       placeholder="请输入物料编码">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>仓库</label>
                                                <select id="ityWhiId" class="form-control select" name="ityWhiId">
                                                </select>
                                                <!--<input type="text" id="stockMaterialTypeQuery" name="stockMaterialTypeQuery"
                                                       class="form-control"
                                                       placeholder="请输入原料类型">-->
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <label>
                                                    库位
                                                </label>
                                                <input type="text" id="ityPosition" name="ityPosition"
                                                       class="form-control"
                                                       placeholder="请输入库位">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 10px;">
                                                <button type="button" class="btn btn-vk" id="btn_inventorySearch">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;搜索&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body"
                                 style="padding-top: 0px;padding-bottom: 0px;margin-top: -50px;height: 600px">
                                <table id="inventoryQueryTable" class="table table-bordered " width="100%"
                                       data-height="600">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" class="btn btn-info" id="btn-selectMaterial-commit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>
<section class="content-header">
    <h1>项目划库存执行</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-inline">
                        <div class="row" style="margin: 0px;">
                            <div class="form-group">
                                <label>
                                    项目编号
                                </label>
                                <label class="control-label">
                                    <input name="pimBeforeProCode" type="text" class="form-control text"
                                           placeholder="请输入项目编号"/>
                                </label>
                            </div>
                            <div class="form-group">
                                <label>
                                    项目名称
                                </label>
                                <label class="control-label">
                                    <input name="pimBeforeProName" type="text" class="form-control text" maxlength="255"
                                           placeholder="请输入项目名称"/>
                                </label>
                            </div>
                            <div class="form-group">
                                <label>
                                    物料描述
                                </label>
                                <label class="control-label">
                                    <input name="pimMatDesc" type="text" class="form-control text" maxlength="255"
                                           placeholder="请输入物料描述"/>
                                </label>
                            </div>

                            <div class="form-group">
                                <label>
                                    标记人
                                </label>
                                <input name="pimProposerName" type="text" class="form-control text" maxlength="255"
                                       placeholder="请输入标记人信息"/>
                            </div>
                            <div class="form-group">
                                <label>
                                    划拨状态
                                </label>
                                <select name="pimAppStatus" class="form-control select">
                                    <option value="-1">全部</option>
                                    <option value="3">未执行</option>
                                    <option value="4">已执行</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>
                                    物料分类
                                </label>
                                <select name="ityMatType" id="ityMatType" class="form-control select">
                                    <option value="">全部</option>
                                    <option value="2">外协件</option>
                                    <option value="4">铝料</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>标记日期</label>
                                <input type="text" class="form-control datepicker" id="startOdrMakeDate"
                                       name="startOdrMakeDate" readonly="readonly"/>
                                <span>至</span>
                                <input type="text" class="form-control datepicker" id="endOdrMakeDate"
                                       name="endOdrMakeDate" readonly="readonly"/>
                            </div>
                            <div class="form-group ">
                                <button type="button" class="btn btn-success" id="btn-search">搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar">
                    <button type="button" shiro:hasPermission="halinv:halprowarexec:edit"
                            class="btn btn-success" onclick="execApply('')">
                        批量执行
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var applyStatusText = ["", "未提交", "已驳回", "未执行", "已执行"];
    var colors = ['', "bg-gray", "bg-red", "bg-yellow", "bg-green"];

    /**
     *@FunctionName: revokeApply
     *@Description: 撤销
     *@Author: TH
     *@CreateDate: 2020/5/9 8:28
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function revokeApply(pimId) {
        js.modal.confirm("您确认要撤销此标记吗？", function () {
            $.post(ctx + 'half/halInvManage/proToInvExc/revoke', {
                pimIds: pimId
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                    js.modal.success(result.msg);
                } else if (result.type == "ERROR") {
                    js.modal.fail(result.msg);
                }
            }, 'json');
        });
    }


    /**
     *@FunctionName: execApply
     *@Description: 执行
     *@Author: TH
     *@CreateDate: 2020/5/9 8:28
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function execApply(pimIds) {
        js.modal.confirm("您确认要执行此标记吗？", function () {
            if (pimIds == '') {
                $('input[name="cb_change"]').each(function () {
                    if (!$(this).prop("disabled")) {
                        if ($(this).prop("checked")) {
                            pimIds += $(this).attr("data") + ",";
                        }
                    }
                })
                pimIds = pimIds.substring(0, pimIds.length - 1);
            }
            if (pimIds == '') {
                js.modal.warning("请选择要执行的串料申请！");
                return;
            }
            $.post(ctx + 'half/halInvManage/proToInvExc/exec', {
                pimIds: pimIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                    js.modal.success(result.msg);
                }
                if (result.type == "ERROR") {
                   js.modal.fail(result.msg);
                }
            }, 'json');
        });
    }
    /**
     *@FunctionName: reject
     *@Description: 驳回
     *@Author: TH
     *@CreateDate: 2020/5/8 15:21
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function reject(pimIds) {
        js.modal.confirm("尊敬的用户，您确认要驳回此标记吗？", function () {
            if (pimIds == '') {
                $('input[name="cb_change"]').each(function () {
                    if (!$(this).prop("disabled")) {
                        if ($(this).prop("checked")) {
                            pimIds += $(this).attr("data") + ",";
                        }
                    }
                })
                pimIds = pimIds.substring(0, pimIds.length - 1);
            }
            if (pimIds == '') {
                js.modal.warning("请选择要驳回的标记！");
                return;
            }
            $.post(ctx + 'half/halInvManage/proToInvExc/reject', {
                pimIds: pimIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    $("#selectAll").prop('checked', false);
                    js.table.refresh(table);
                }
            }, 'json');
        });
    }
    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: TH
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: TH
     *@CreateDate: 2020/4/8 15:20
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectAll(obj) {
        $('input[name="cb_change"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })

    }


    $(function () {
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "half/halInvManage/proToInvExc/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "ipmId",
            onLoadSuccess: function () {
                $('#bootstrap-table thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#bootstrap-table tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: [
                {
                    title: '   <input title="" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                    width: '80',
                    field: 'pimId',
                    formatter: function (value, row, index) {
                        var disabled = 'disabled="disabled"';
                        if (row.pimAppStatus == 3) {
                            disabled = "";
                        }
                        return '<input  style="width: 30px;height: 30px" ' + disabled + ' id="cb_change' + row.pimId + '" name="cb_change" data="' + row.pimId + '"  type="checkbox" />';
                    }
                },
                {
                    title: '序号', field: 'pimId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '物料分类', field: 'ityMatType',
                    formatter: function (value, row, index) {
                        if (value == 2) {
                            return "外协件";
                        }else if(value == 3){
                            return "制作件";
                        }else if(value == 4){
                            return "铝料";
                        }else {
                            return value;
                        }
                    }},
                {title: '物料描述', field: 'pimMatDesc', width: '150'},
                {title: 'SAP物料编码', field: 'pimSapCode', width: '150'},
                {title: '图号', field: 'ityDrawingNumber'},
                {title: '标记数量', field: 'pimNum'},
                {title: '单位', field: 'pimNumUnit'},
                {title: '标记重量', field: 'pimWeight'},
                {title: '项目编号', field: 'pimBeforeProCode'},
                {title: '项目名称', field: 'pimBeforeProName', width: '150'},
                /*{
                    title: '仓库类型', field: 'pimItyType', width: '150', formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        if (value == 'p') {
                            return "外购件库";
                        }
                        if (value == 'm') {
                            return "原料库";
                        }
                        if (value == 'h') {
                            return "成品库";
                        }
                        return value;
                    }
                },*/
                {title: '标记人', field: 'pimProposerName'},
                {title: '标记日期', field: 'pimDate',width:'90'},
                {
                    title: '划拨说明', field: 'pimRemark'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '划拨状态', field: 'pimAppStatus'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return '<span class="badge ' + colors[value] + '">' + applyStatusText[value] + '</span> ';
                    }
                },
                {
                    title: '操作', field: 'pimId',width:'110',
                    formatter: function (value, row, index) {
                        var htmlText = "";
                        if ((row.pimAppStatus == 4 || row.pimAppStatus == 2) && hasP("halinv:halprowarexec:edit")) {
                            htmlText += '<button class="btn btn-primary btn-xs" onclick="revokeApply(' + row.pimId + ')">撤销</button>';
                            return htmlText
                        }
                        if (row.pimAppStatus == 3 && hasP("halinv:halprowarexec:edit")) {
                            htmlText += '<button class="btn btn-success btn-xs" onclick="execApply(' + row.pimId + ')">执行</button>';
                            htmlText += '<button onclick="reject(' + row.pimId + ')" class="btn btn-xs btn-danger">驳回</button>';
                        }
                        return htmlText;
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });
    });
</script>
</body>
</html>
